package day0415;

public class LeetCode101 {
    /**
     * 504. 对称二叉树
     * 简单
     * <p>
     * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
     * <p>
     * <p>
     * 示例 1:
     * 输入：root = [1,2,2,3,4,4,3]
     * 输出：true
     */
    public static void main(String[] args) {

    }

    public boolean isSymmetric(TreeNode root) {
        return check(root, root);
    }

    private boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);

    }

}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}